﻿using System.ComponentModel.DataAnnotations;

namespace Core.Identity.Common.Auth.Jwt;

/// <summary>
/// JWT配置选项
/// </summary>
public class JwtOptions : IValidatableObject
{
    /// <summary>
    /// Key
    /// </summary>
    public string Key { get; set; } = string.Empty;

    /// <summary>
    /// Token过期时间（分钟）
    /// </summary>
    public int TokenExpirationInMinutes { get; set; } = 60;

    /// <summary>
    /// 刷新Token过期时间（天）
    /// </summary>
    public int RefreshTokenExpirationInDays { get; set; } = 7;

    /// <summary>
    /// 校验
    /// </summary>
    /// <param name="validationContext"></param>
    /// <returns></returns>
    public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
    {
        if (string.IsNullOrEmpty(Key))
        {
            yield return new ValidationResult("No Key defined in JwtSettings config", [nameof(Key)]);
        }
    }
}
